﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：YaxNodeInfo
// 文件功能描述：设备组管理
//
// 
// 创建标识：2012-02-09 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class YaxNodeInfo
    {
        /// <summary>
        /// 主键，设备组ID
        /// </summary>
        public int NodeID
        {
            get;
            set;
        }
        /// <summary>
        /// 设备组名称
        /// </summary>
        public string Nodename
        {
            get;
            set;
        }
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark
        {
            get;
            set;
        }

        private DataAccessYaxNode dar;
        private int YaxNodecount;
        public int _YaxNodecount
        {
            get { return YaxNodecount; }
        }
        public YaxNodeInfo(bool isgetcount)
        {
            dar = new DataAccessYaxNode();
            if (isgetcount)
            {
                YaxNodecount = GetYaxNodeCount();
            }
        }
        public YaxNodeInfo()
        { }

        /// <summary>
        /// 获取设备组数量
        /// </summary>
        /// <returns></returns>
        private int GetYaxNodeCount()
        {
            return dar.GetYaxNodeCount();
        }

        /// <summary>
        /// 获取设备组信息（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<YaxNodeInfo> SelYaxNodeInfo(int pagesize, int startindex, string strquery)
        {
            IList<YaxNodeInfo> yaxlist = new List<YaxNodeInfo>();
            YaxNodeInfo yaxinfo;
            DataSet ds = dar.SelYaxNodeInfo(pagesize, startindex, strquery);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                yaxinfo = new YaxNodeInfo()
                {
                    NodeID = Convert.ToInt32(item["NodeID"]),
                    Nodename = item["Nodename"].ToString(),
                    Remark = item["Remark"].ToString()
                };
                yaxlist.Add(yaxinfo);
            }
            return yaxlist;
        }

        /// <summary>
        /// 删除设备组
        /// </summary>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public int DeleteYaxNode(string id)
        {
            return dar.DeleteYaxNode(id);
        }

        /// <summary>
        /// 保存设备组(新增界面下)
        /// </summary>
        /// <param name="rolepara"></param>
        /// <returns></returns>
        public int SaveYaxNode(YaxNodeInfo yax)
        {
            object[] yaxpara = new object[] { yax.Nodename, yax.Remark };
            return dar.SaveYaxNode(yaxpara);
        }

        /// <summary>
        /// 根据编号获取一条设备组信息
        /// </summary>
        /// <param name="supplierNo"></param>
        /// <returns></returns>
        public YaxNodeInfo GetYaxNodeInfoOne(string id)
        {
            dar = new DataAccessYaxNode();
            DataSet ds = dar.GetYaxNodeInfoOne(id);
            YaxNodeInfo info = new YaxNodeInfo();
            info.NodeID = int.Parse(ds.Tables[0].Rows[0]["NodeID"].ToString());
            info.Nodename = ds.Tables[0].Rows[0]["Nodename"].ToString();
            info.Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
            return info;
        }

        /// <summary>
        /// 保存设备组(修改界面下)
        /// </summary>
        /// <param name="rolepara"></param>
        /// <returns></returns>
        public int SaveYaxNodeEdit(YaxNodeInfo yax)
        {
            object[] yaxpara = new object[] { yax.NodeID, yax.Nodename, yax.Remark };
            return dar.SaveYaxNodeEdit(yaxpara);
        }

        /// <summary>
        /// 获取设备组信息(不分页）
        /// </summary>
        /// <returns></returns>
        public IList<YaxNodeInfo> SelYaxNodeInfo(string condition)
        {
            IList<YaxNodeInfo> yaxlist = new List<YaxNodeInfo>();
            YaxNodeInfo yaxinfo;
            DataSet ds = dar.SelYaxNodeInfo(condition);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                yaxinfo = new YaxNodeInfo()
                {
                    NodeID = Convert.ToInt32(item["NodeID"]),
                    Nodename = item["Nodename"].ToString(),
                    Remark = item["Remark"].ToString()
                };
                yaxlist.Add(yaxinfo);
            }
            return yaxlist;            
        }

        public static string GetYaxNodeName(string yid)
        {
            return DataAccessYaxNode.GetYaxNodeName(yid);
        } 
    }
}
